﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace CJJCH.Web.Manage
{
    public partial class ManageAdd : PowerBase
    {
        CJJCH.BLL.T_NET_Manager bll_manager = new BLL.T_NET_Manager();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.form1.DefaultButton = "btnSave";
            LTP.Common.ButtonClass.ButtonOnClick(this.Page, btnSave, "checkform()", false);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string error = CheckInput();
            if (error == "")
            {
                CJJCH.Model.T_NET_Manager model = new CJJCH.Model.T_NET_Manager();
                model.ID = Guid.NewGuid();
                model.BuildDate = DateTime.Now;
                model.ManagerID = SessionManagerID;
                model.RealName = LTP.Common.StringClass.EncodeString(this.txtRealName.Text.Trim());
                model.UserName = LTP.Common.StringClass.EncodeString(this.txtUserName.Text.Trim());
                model.UserTel = LTP.Common.StringClass.EncodeString(this.txtUserTel.Text.Trim());
                model.UserPwd = LTP.Common.StringClass.EncryptPassword(this.txtUserPw1d.Text.Trim(), LTP.Common.StringClass.PasswordFormat.MD5_32);
                error = bll_manager.AddManager(model);
                if (error == "")
                {
                    LTP.Common.WindowClass.WindowGoHref("管理员添加完成！", "ManageList.aspx");
                }
                else
                {
                    LTP.Common.WindowClass.WindowBack(error);
                }
            }
            else
            {
                LTP.Common.WindowClass.WindowBack(error);
            }
        }

        private string CheckInput()
        {
            StringBuilder error = new StringBuilder();
            if (txtUserName.Text.Trim() == "")
            {
                error.Append("请输入登陆账户！\\n");
            }

            if (txtUserPw1d.Text.Trim() == "")
            {
                error.Append("请输入登录密码！\\n");
            }
            if (txtUserPw2d.Text.Trim() == "")
            {
                error.Append("请输入确认密码！\\n");
            }
            if (txtUserPw1d.Text.Trim() != txtUserPw2d.Text.Trim())
            {
                error.Append("两次输入密码不一致！\\n");
            }
            if (txtRealName.Text.Trim() == "")
            {
                error.Append("请输入姓名！\\n");
            }
            if (txtUserTel.Text.Trim() == "")
            {
                error.Append("请输入联系电话！\\n");
            }
            //else if (!LTP.Common.CheckInput.CheckPhone(txtUserTel.Text.Trim()) || !LTP.Common.CheckInput.CheckMobile(txtUserTel.Text.Trim()))
            //{
            //    error.Append("请输入正确的联系电话！\\n");
            //}
            return error.ToString();
        }

    }
}